package de.clapp.backend.requests;

import java.lang.reflect.Type;

import de.clapp.client.musicbox.MusicBoxModel;

public class MusicGetCurrentTimeRequest implements ServerRequest
{
    private static final long serialVersionUID = -4861252674293402670L;
    
    private int currentPosition;

    @Override
    public Type getReturnType()
    {
        return int.class;
    }

    @Override
    public Integer getItem()
    {
        return this.currentPosition;
    }

    @Override
    public void setItem(Object item)
    {
        this.currentPosition = (Integer) item;
    }

    @Override
    public Object execute()
    {
        float percent = MusicBoxModel.mediaPlayerComponent.getMediaPlayer().getPosition();
        int length = (int) (MusicBoxModel.mediaPlayerComponent.getMediaPlayer().getLength() / 1000);
        float value = percent * length;
        this.currentPosition = (int) value;
        return this.currentPosition;
    }
}
